package com.epalmpay.service.yunstream.datatransfer.impl;

import com.epalmpay.exception.ApplicationException;
import com.epalmpay.entity.*;
import com.epalmpay.enumdef.BizEnum;
import com.epalmpay.enumdef.CommonEnum;
import com.epalmpay.mapper.*;
import com.epalmpay.service.yunstream.datatransfer.IDataTransferService;
import com.epalmpay.util.DateUtil;
import com.epalmpay.util.Logger;
import com.epalmpay.util.StringUtil;
import com.epalmpay.util.Tools;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("dataTransferService")
public class DataTransferServiceImpl implements IDataTransferService {

	protected Logger logger = Logger.getLogger(this.getClass());

	@Resource
	private UserbaseMapper userbaseMapper;
	@Resource
	private MemberMapper memberMapper;
	@Resource
	private MemberCardMapper memberCardMapper;
	@Resource
	private MemberAddressMapper memberAddressMapper;
	@Resource
	private TradeOfflineMapper tradeOfflineMapper;
	@Resource
	private YsOilcardOrderMapper ysOilcardOrderMapper;
	@Resource
	private YsFlowChargeOrderMapper flowChargeMapper;
	@Resource
	private YsOilcardMemberMapper ysOilcardMemberMapper;

	@Resource(name="transactionManager")
	private DataSourceTransactionManager transactionManager;

	//云流groupId
	public static Long GROUP_Id = 2L;

	//云流会员图片路径
	public static String PICTURE_PATH = "http://file.ebank007.com/file/ebos/member/" + String.valueOf(GROUP_Id) + "";

	DbHelper dbUitil = null;

	public int DataFromOldVersion(int step) throws Exception{
		int result = 0;


		try {
			dbUitil=DbHelper.getDBHelper();
			if(dbUitil.openDatabase()) {
				//10、会员信息(会员注册信息、绑定卡信息、会员地址信息)
				if(step == 10) {
					memberDeal();
				}
				else if(step == 11) {
					//会员地址信息处理
					memberAddressDeal();
				}
				else if(step == 12) {
					//会员油卡信息处理
					memberOilCardDeal();
				}
				//2、商城商品、商品商城订单交易(迁移)(商品数量不多，手动建立)
				else if(step == 20) {
					orderDeal();
				}
				//3、油卡套餐及油卡绑定卡信息(迁移)
				else if(step == 30) {
					//直接数据库导入
//					INSERT INTO `t_ys_oilcard`(`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('18', '95', '950', 'ZSH', '2017-07-24 09:41:13', '2017-09-01 12:20:04', 'yunliu2', 'yunliu', '0', '9', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('19', '90', '950', 'ZSH', '2017-06-25 11:28:00', '2017-09-01 12:19:59', 'yunliu', 'yunliu', '0', '12', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('20', '97', '950', 'ZSH', '2017-06-25 11:28:26', '2017-09-01 12:19:07', 'yunliu', 'yunliu', '0', '6', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('21', '98', '950', 'ZSH', '2017-06-25 11:28:48', '2017-09-01 12:19:53', 'yunliu', 'yunliu', '0', '3', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('22', '99', '950', 'ZSH', '2017-06-25 11:29:14', '2017-08-24 15:22:54', 'yunliu', 'yunliu', '0', '1', '100000', '0', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('23', '86', '950', 'ZSY', '2017-06-25 11:29:43', '2017-09-01 12:20:55', 'yunliu', 'yunliu', '0', '9', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('24', '87', '950', 'ZSY', '2017-06-25 11:30:15', '2017-09-01 12:20:50', 'yunliu', 'yunliu', '0', '6', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('25', '88', '950', 'ZSY', '2017-06-25 11:30:47', '2017-09-01 12:20:44', 'yunliu', 'yunliu', '0', '3', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('26', '89', '950', 'ZSY', '2017-06-25 11:31:15', '2017-08-24 15:22:59', 'yunliu', 'yunliu', '0', '1', '100000', '0', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('28', '83', '950', 'ZSY', '2017-07-24 09:40:19', '2017-09-01 12:20:34', 'yunliu2', 'yunliu', '0', '12', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('30', '1', '93000', 'ZSH', '2017-07-28 13:32:38', '2017-09-01 12:17:54', 'yunliu', 'yunliu', '0', '3', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('31', '1', '930', 'ZSH', '2017-07-28 13:33:48', '2017-08-24 15:23:05', 'yunliu', 'yunliu', '0', '3', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('32', '2', '910', 'ZSH', '2017-07-28 13:35:22', '2017-09-01 12:19:30', 'yunliu', 'yunliu', '0', '3', '100000', '1', '-99',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('33', '2', '910', 'ZSH', '2017-07-28 13:36:23', '2017-08-24 15:23:10', 'yunliu', 'yunliu', '0', '6', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('34', '3', '890', 'ZSH', '2017-07-28 13:36:52', '2017-08-24 15:23:17', 'yunliu', 'yunliu', '0', '9', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('35', '4', '870', 'ZSH', '2017-07-28 13:38:09', '2017-08-24 15:23:23', 'yunliu', 'yunliu', '1', '12', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('36', '5', '930', 'ZSY', '2017-07-28 13:40:25', '2017-08-24 15:23:38', 'yunliu', 'yunliu', '0', '3', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('37', '6', '910', 'ZSY', '2017-07-28 13:41:16', '2017-08-24 15:23:43', 'yunliu', 'yunliu', '0', '6', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('38', '7', '890', 'ZSY', '2017-07-28 13:42:18', '2017-08-24 15:23:49', 'yunliu', 'yunliu', '0', '9', '100000', '1', '1',50,100,60);
//					INSERT INTO `t_ys_oilcard` (`id` ,`sort` ,`discount`, `oilcard_type` ,`gmt_create` ,`gmt_modified` ,`creater` ,`updater` ,`is_default` ,`count_num`,`limit_amount` ,`type` ,`is_startuse`,`group_id`,`sale_base`,`sale_amount`) VALUES ('39', '8', '870', 'ZSY', '2017-07-28 13:43:21', '2017-08-24 15:23:54', 'yunliu', 'yunliu', '1', '12', '100000', '1', '1',50,100,60);

				}
				//4、交易记录(消费(在商城订单中处理了)、转账、充值、提现、信用卡还款、油卡充值、流量卡充值、退款(无)等)
				else if(step == 40) {
					//转账交易处理
					transferTradeDeal();
				}
				else if(step == 41) {
					//充值交易处理
					rechargeTradeDeal();
				}
				else if(step == 42) {
					//提现、信用卡还款
					withdrawalTradeDeal();
				}
				else if(step == 43) {
					//油卡充值
					oilCardRechargeTradeDeal();
				}
				else if(step == 44) {
					//流量卡充值
					flowRechargeTradeDeal();
				}
			}
		} catch (Exception e) {
			//dbUitil.closeDataBase();
			e.printStackTrace();
		}finally {
			dbUitil.closeDataBase();
		}

		return result;
	}

	//会员处理
	public void memberDeal() throws Exception{

		List<Map<String,String>> members = dbUitil.findAllMember();

		for(Map<String,String> map:members){
			memberInfoDeal(map);
		}
	}

	public void memberInfoDeal(Map<String,String> map) throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		String member_id = map.get("member_id");
		String member_virtual_card = map.get("member_virtual_card");
		String member_role_id = map.get("member_role_id");
		String member_customer_name = map.get("member_customer_name");
		String member_id_number = map.get("member_id_number");
		String member_pay_pwd = map.get("member_pay_pwd");
		String member_login_pwd = map.get("member_login_pwd");
		String member_mobile_phone = map.get("member_mobile_phone");
		String member_sex = map.get("member_sex");
		String member_email = map.get("member_email");
		String member_openid = map.get("member_openid");
		String member_regtime = map.get("member_regtime");
		String member_balance_b = map.get("member_balance_b");
		String member_balance = map.get("member_balance");
		String member_verify_status = map.get("member_verify_status");
		String member_accounts_status = map.get("member_accounts_status");
		String member_status = map.get("member_status");
		String system_userid = map.get("system_userid");
		String img_url = map.get("img_url");

		logger.info("会员ID:"+member_id+"处理中。。。");

		int result = 0;
		try {
			Date regtime = new Date(Long.parseLong(member_regtime)*1000);

			//插入用户表
			Userbase userbase = new Userbase();
			userbase.setGmtCreate(regtime);
			userbase.setGmtModified(regtime);
			userbase.setUsername(member_mobile_phone);
			userbase.setPassword(member_login_pwd);
			userbase.setStatus(0);
			userbase.setUserType(CommonEnum.UserType.User.getType());
			userbase.setGroupId(GROUP_Id);
			result = userbaseMapper.insertKey(userbase);

			//插入member表
			Member member = new Member();
			member.setGroupId(GROUP_Id);
			member.setName(member_customer_name);
			member.setThirdUserId(member_openid);
			//member.setOpenid(member_openid);
			member.setPhone(member_mobile_phone);
			member.setSex("0".equals(member_sex)?2:1);
            member.setIdNo(member_id_number);
            member.setTradePassword(member_pay_pwd);
            if("1".equals(member_accounts_status)) {
				member.setVirtualCard(member_virtual_card);
				member.setWalletStatus(1);
			}
			member.setGmtModified(regtime);
			member.setGmtCreate(regtime);
			member.setUserId(userbase.getId());
			member.setApproveStatus("1".equals(member_status)?1:0);
			member.setCardNo(DateUtil.getMonth()+ Tools.getRandomNum(6));
			if(img_url != null) {
//				String imgUrl = img_url.substring(img_url.lastIndexOf("/"));
//				member.setPicture(PICTURE_PATH + imgUrl);
				member.setPicture(img_url);
			}
			member.setGradeId(2L);//普通会员
			result = memberMapper.insert(member);

			//会员的绑卡数据(信用卡与借记卡、提现卡)
			List<Map<String, String>> cardList = dbUitil.findMemberCardInfo(Long.parseLong(member_id));
			for(Map<String, String> card:cardList){
				String tx_card_org_order_num = card.get("tx_card_org_order_num");
				String tx_card_num = card.get("tx_card_num");
				String tx_card_account_type = card.get("tx_card_account_type");
				String tx_card_issuer_id = card.get("tx_card_issuer_id");
				String tx_card_integral = card.get("tx_card_integral");
				String tx_card_info = card.get("tx_card_info");
				String tx_card_desc = card.get("tx_card_desc");
				String tx_card_acc_name = card.get("tx_card_acc_name");
				String tx_card_no = card.get("tx_card_no");
				String tx_card_mobile = card.get("tx_card_mobile");
				String tx_card_type = card.get("tx_card_type");
				String tx_card_status = card.get("tx_card_status");
				String tx_card_cvn = card.get("tx_card_cvn");
				String tx_card_expdate = card.get("tx_card_expdate");
				String tx_card_account_type_value = card.get("tx_card_account_type_value");

				MemberCard memberCard = new MemberCard();
				memberCard.setGmtCreate(new Date());
				memberCard.setGmtModified(new Date());
				memberCard.setMemberId(member.getId());
				memberCard.setCardNum(tx_card_num);
				memberCard.setCardType("1".equals(tx_card_account_type_value)?2:1);
				//memberCard.setIssuerBankId();
				memberCard.setIssuerBankName(tx_card_issuer_id);
				memberCard.setBankIntegral(tx_card_integral);
				memberCard.setIdNo(tx_card_no);
				memberCard.setIdName(tx_card_acc_name);
				memberCard.setCardMobile(tx_card_mobile);
				memberCard.setBindCardType("1".equals(tx_card_type)?2:1);
                memberCard.setCardStatus("1".equals(tx_card_status)?2:1);
                memberCard.setCardCvn(tx_card_cvn);
                memberCard.setCardExpdate(tx_card_expdate);
				result = memberCardMapper.insert(memberCard);

				logger.info("会员ID:"+member_id+"处理银行卡："+tx_card_num+"完成...");
			}

			logger.info("会员ID:"+member_id+"处理完成。。。");
			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
			logger.error("会员ID:"+member_id+"处理异常。。。");
			throw new ApplicationException("500", "commit transaction exception"+"会员ID:"+member_id+"处理异常。。。");
		}

	}

	public void memberAddressDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		int result = 0;
		Date date = new Date();
		try {
			//获取所有的地址记录
			List<Map<String, String>> addressList = dbUitil.findMemberAddress();
			for(Map<String, String> address:addressList){
				String address_id = address.get("address_id");
				String address_member_id = address.get("address_member_id");
				String address_customer_name = address.get("address_customer_name");
				String address_mobile_phone = address.get("address_mobile_phone");
				String address_city = address.get("address_city");
				String address_area = address.get("address_area");
				String default_select = address.get("default_select");
				String address_status = address.get("status");
				String member_mobile_phone = address.get("member_mobile_phone");

				//查询新的会员id
				Member member = memberMapper.queryNameByPhone(member_mobile_phone,GROUP_Id);
				if(member==null)
					continue;
				//此处插入会员地址逻辑
				MemberAddress memberAddress = new MemberAddress();
				memberAddress.setMemberId(member.getId());
				memberAddress.setCustomerName(address_customer_name);
				memberAddress.setPhone(address_mobile_phone);
				memberAddress.setCity(address_city);
				memberAddress.setArea(address_area);
				memberAddress.setIsDefault("1".equals(default_select)?Boolean.TRUE:Boolean.FALSE);
				memberAddress.setStatus("1".equals(address_status)?1:0);
				result = memberAddressMapper.insert(memberAddress);

				logger.info("会员地址ID:"+address_id+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
		}

	}

	public void memberOilCardDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		int result = 0;
		Date date = new Date();
		try {
			//获取所有的油卡记录
			List<Map<String, String>> recordList = dbUitil.findMemberOilCard();
			for(Map<String, String> record:recordList){
				String member_id = record.get("member_id");
				String oilcard_type = record.get("oilcard_type");
				String oilcard_number = record.get("oilcard_number");
				String oilcard_owen = record.get("oilcard_owen");
				String oilcard_phone = record.get("oilcard_phone");
				String create_time = record.get("create_time");
				String update_time = record.get("update_time");
				String isdefault = record.get("isdefault");
				String member_mobile_phone = record.get("member_mobile_phone");

				//查询新的会员id
				Member member = memberMapper.queryNameByPhone(member_mobile_phone,GROUP_Id);
				if(member==null)
					continue;
				//此处插入会员油卡逻辑
				YsOilcardMember ysOilcardMember = new YsOilcardMember();
				ysOilcardMember.setGmtCreate(DateUtil.fomatDate(create_time,DateUtil.sdfTime));
				ysOilcardMember.setGmtModified(DateUtil.fomatDate(update_time,DateUtil.sdfTime));
				ysOilcardMember.setMemberId(member.getId());
				ysOilcardMember.setOilcardType(oilcard_type);
				ysOilcardMember.setOilcardNumber(oilcard_number);
				ysOilcardMember.setOilcardName(oilcard_owen);
				ysOilcardMember.setOilcardPhone(oilcard_phone);
				ysOilcardMember.setIsDefault("1".equals(isdefault)?Boolean.TRUE:Boolean.FALSE);
				result = ysOilcardMemberMapper.insert(ysOilcardMember);

				logger.info("会员油卡ID:"+oilcard_number+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
		}

	}

	public void orderDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		//logger.info("会员ID:"+member_id+"处理中。。。");

		int result = 0;
		try {
			//获取所有的订单记录
			List<Map<String, String>> orderList = dbUitil.findAllGoodOrders();
			for(Map<String, String> order:orderList){
				String goods_order_id = order.get("goods_order_id");
				String goods_order_member_id = order.get("goods_order_member_id");
				String goods_order_code = order.get("goods_order_code");
				String goods_order_number = order.get("goods_order_number");
				String goods_order_price = order.get("goods_order_price");
				String goods_order_datetime = order.get("goods_order_datetime");
				String goods_order_fk_datetime = order.get("goods_order_fk_datetime");
				String goods_order_fh_datetime = order.get("goods_order_fh_datetime");
				String goods_order_fh_name = order.get("goods_order_fh_name");
				String goods_order_fh_code = order.get("goods_order_fh_code");
				String goods_order_address_customer_name = order.get("goods_order_address_customer_name");
				String goods_order_address_mobile_phone = order.get("goods_order_address_mobile_phone");
				String goods_order_address_city = order.get("goods_order_address_city");
				String goods_order_address_area = order.get("goods_order_address_area");
				String goods_order_complete_datetime = order.get("goods_order_complete_datetime");
				String goods_order_qx_datetime = order.get("goods_order_qx_datetime");
				String goods_order_status = order.get("goods_order_status");
				String delete_status = order.get("delete_status");
				String member_mobile_phone = order.get("member_mobile_phone");

				//查询新的会员id
				Member member = memberMapper.queryNameByPhone(member_mobile_phone,GROUP_Id);
				if(member==null)
					continue;
				//此处插入实物订单逻辑

				//查询订单明细记录
				List<Map<String, String>> itemList = dbUitil.getGoodOrderItem(Long.parseLong(goods_order_id));
				for(Map<String, String> item:itemList){
					String item_id = item.get("item_id");
					String item_goods_order_id = item.get("item_goods_order_id");
					String item_goods_id = item.get("item_goods_id");
					String item_goods_name = item.get("item_goods_name");
					String item_goods_image = item.get("item_goods_image");
					String item_goods_original_price = item.get("item_goods_original_price");
					String item_goods_promotion_price = item.get("item_goods_promotion_price");
					String item_goods_number = item.get("item_goods_number");

					//此处插入实物订单明细逻辑
				}

				//插入交易逻辑(仅插入交易成功的记录)
				Map<String, String> trade = dbUitil.getGoodOrderTrade(Long.parseLong(goods_order_id));
				if(trade != null) {
					String goods_pay_id = trade.get("goods_pay_id");
					String goods_pay_order_id = trade.get("goods_pay_order_id");
					String goods_pay_goods_order_id = trade.get("goods_pay_goods_order_id");
					String goods_pay_order_time = trade.get("goods_pay_order_time");
					String goods_pay_price = trade.get("goods_pay_price");
					String goods_pay_status = trade.get("goods_pay_status");
					String goods_pay_type = trade.get("goods_pay_type");
					String goods_pay_ordernum = trade.get("goods_pay_ordernum");
					//////////////////////////////////
					String order_id = trade.get("order_id");
					String order_type = trade.get("order_type");
					String order_userid = trade.get("order_userid");
					String order_groupid = trade.get("order_groupid");
					String order_merchantid = trade.get("order_merchantid");
					String order_orgtrandatetime = trade.get("order_orgtrandatetime");
					String order_systrace_num = trade.get("order_systrace_num");
					String order_resp_code = trade.get("order_resp_code");
					String order_msg_txt = trade.get("order_msg_txt");
					String order_datetime = trade.get("order_datetime");
					String relate_order_id = trade.get("relate_order_id");

					TradeOffline tradeOffline = new TradeOffline();
					Date ordertime = new Date(Long.parseLong(goods_pay_order_time)*1000);
					tradeOffline.setGmtCreate(ordertime);
					tradeOffline.setGmtModified(ordertime);
					tradeOffline.setGroupId(GROUP_Id);
					//tradeOffline.setOrderId();
					tradeOffline.setPayerId(member.getId());
					tradeOffline.setPayerName(member.getName());
					tradeOffline.setPayerType((byte)CommonEnum.UserType.User.getType());
					tradeOffline.setReceiverId(String.valueOf(GROUP_Id));
					tradeOffline.setReceiverName("云流");
					tradeOffline.setReceiverType((byte)CommonEnum.UserType.BusinessManager.getType());
					tradeOffline.setTransactionType((byte)BizEnum.TransactionType.Consumption.getType());
					tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());
					tradeOffline.setOrderAmount(Integer.parseInt(goods_pay_price==null?"0":goods_pay_price));
					tradeOffline.setRealAmount(Integer.parseInt(goods_pay_price==null?"0":goods_pay_price));
					switch (Integer.parseInt(goods_pay_type)){
						case 1:
							tradeOffline.setPayType((byte)BizEnum.PaymentType.AliPay.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							break;
						case 2:
							tradeOffline.setPayType((byte)BizEnum.PaymentType.WebChat.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							break;
						case 3:
							tradeOffline.setPayType((byte)BizEnum.PaymentType.BankCard.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							break;
						case 4:
							tradeOffline.setPayType((byte)BizEnum.PaymentType.Wallet.getType());
							tradeOffline.setIsWallet(Boolean.TRUE);
							break;
						default:
							break;
					}
					tradeOffline.setTransactionStatus((byte)BizEnum.TransactionStatus.Success.getType());

					tradeOffline.setGoodType((byte)CommonEnum.GoodType.Goods.getType());
					result = tradeOfflineMapper.insertSelective(tradeOffline);
				}
				logger.info("商品订单ID:"+goods_order_id+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
		}

	}

	public void transferTradeDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		//logger.info("会员ID:"+member_id+"处理中。。。");

		int result = 0;
		try {
			//获取所有的订单记录
			List<Map<String, String>> items = dbUitil.getAllTransferTrade();
			for(Map<String, String> item:items){
				String transfer_id = item.get("transfer_id");
				String transfer_order_id = item.get("transfer_order_id");
				String transfer_order_num = item.get("transfer_order_num");
				String transfer_order_time = item.get("transfer_order_time");
				String transfer_tran_amt = item.get("transfer_tran_amt");
				String transfer_order_currency = item.get("transfer_order_currency");
				String transfer_to_userid = item.get("transfer_to_userid");
				String transfer_userid_phone = item.get("transfer_userid_phone");
				String transfer_to_username = item.get("transfer_to_username");
				String transfer_status = item.get("transfer_status");
				String transfer_outer_orderid = item.get("transfer_outer_orderid");
				String transfer_handlingcharge = item.get("transfer_handlingcharge");
				//////////////////////////////////
				String order_id = item.get("order_id");
				String order_type = item.get("order_type");
				String order_userid = item.get("order_userid");
				String order_userid_phone = item.get("order_userid_phone");
				String order_groupid = item.get("order_groupid");
				String order_merchantid = item.get("order_merchantid");
				String order_orgtrandatetime = item.get("order_orgtrandatetime");
				String order_systrace_num = item.get("order_systrace_num");
				String order_resp_code = item.get("order_resp_code");
				String order_msg_txt = item.get("order_msg_txt");
				String order_datetime = item.get("order_datetime");
				String relate_order_id = item.get("relate_order_id");

				//查询新的会员id
				Member transfermember = memberMapper.queryNameByPhone(transfer_userid_phone,GROUP_Id);
				Member ordermember = memberMapper.queryNameByPhone(order_userid_phone,GROUP_Id);
				if(transfermember==null || ordermember==null)
					continue;

				TradeOffline tradeOffline = new TradeOffline();
				Date ordertime = new Date(Long.parseLong(transfer_order_time)*1000);
				tradeOffline.setGmtCreate(ordertime);
				tradeOffline.setGmtModified(ordertime);
				tradeOffline.setGroupId(GROUP_Id);
				tradeOffline.setOrderId(transfer_order_num);
				tradeOffline.setPayerId(ordermember.getId());
				tradeOffline.setPayerName(ordermember.getName());
				tradeOffline.setPayerType((byte)CommonEnum.UserType.User.getType());
				tradeOffline.setReceiverId(String.valueOf(transfermember.getId()));
				tradeOffline.setReceiverName(transfermember.getName());
				tradeOffline.setReceiverType((byte)CommonEnum.UserType.User.getType());
				tradeOffline.setTransactionType((byte)BizEnum.TransactionType.Transfer.getType());
				tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());
				tradeOffline.setOrderAmount(Integer.parseInt(transfer_tran_amt==null?"0":transfer_tran_amt));
				tradeOffline.setRealAmount(Integer.parseInt(transfer_tran_amt==null?"0":transfer_tran_amt));
				tradeOffline.setPayType((byte)BizEnum.PaymentType.Wallet.getType());
				tradeOffline.setIsWallet(Boolean.TRUE);
				tradeOffline.setTransactionStatus((byte)BizEnum.TransactionStatus.Success.getType());
				tradeOffline.setPayOrderid(transfer_outer_orderid);
				tradeOffline.setMemo("云流转账");
				//tradeOffline.setGoodType((byte)CommonEnum.GoodType.Goods.getType());
				result = tradeOfflineMapper.insertSelective(tradeOffline);

				logger.info("转账订单ID:"+transfer_id+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
		}

	}

	public void rechargeTradeDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		int result = 0;
		try {
			//获取所有的订单记录
			List<Map<String, String>> items = dbUitil.getAllRechargeTrade();
			for(Map<String, String> item:items){
				String recharge_id = item.get("recharge_id");
				String recharge_order_id = item.get("recharge_order_id");
				String recharge_order_num = item.get("recharge_order_num");
				String recharge_order_time = item.get("recharge_order_time");
				String recharge_tran_amt = item.get("recharge_tran_amt");
				String recharge_type = item.get("recharge_type");
				String recharge_bank_name = item.get("recharge_bank_name");
				String recharge_card_id = item.get("recharge_card_id");
				String recharge_qrcode = item.get("recharge_qrcode");
				String recharge_status = item.get("recharge_status");
				String recharge_pay_ordernum = item.get("recharge_pay_ordernum");
				//////////////////////////////////
				String order_id = item.get("order_id");
				String order_type = item.get("order_type");
				String order_userid = item.get("order_userid");
				String order_userid_phone = item.get("order_userid_phone");
				String order_groupid = item.get("order_groupid");
				String order_merchantid = item.get("order_merchantid");
				String order_orgtrandatetime = item.get("order_orgtrandatetime");
				String order_systrace_num = item.get("order_systrace_num");
				String order_resp_code = item.get("order_resp_code");
				String order_msg_txt = item.get("order_msg_txt");
				String order_datetime = item.get("order_datetime");
				String relate_order_id = item.get("relate_order_id");

				//查询新的会员id
				Member ordermember = memberMapper.queryNameByPhone(order_userid_phone,GROUP_Id);
				if(ordermember==null)
					continue;

				TradeOffline tradeOffline = new TradeOffline();
				Date ordertime = new Date(Long.parseLong(recharge_order_time)*1000);
				tradeOffline.setGmtCreate(ordertime);
				tradeOffline.setGmtModified(ordertime);
				tradeOffline.setGroupId(GROUP_Id);
				tradeOffline.setOrderId(recharge_order_num);
				tradeOffline.setPayerId(ordermember.getId());
				tradeOffline.setPayerName(ordermember.getName());
				tradeOffline.setPayerType((byte)CommonEnum.UserType.User.getType());
				tradeOffline.setReceiverId(String.valueOf(ordermember.getId()));
				tradeOffline.setReceiverName(ordermember.getName());
				tradeOffline.setReceiverType((byte)CommonEnum.UserType.User.getType());
				tradeOffline.setTransactionType((byte)BizEnum.TransactionType.Recharge.getType());
				tradeOffline.setOrderAmount(Integer.parseInt(recharge_tran_amt==null?"0":recharge_tran_amt));
				tradeOffline.setRealAmount(Integer.parseInt(recharge_tran_amt==null?"0":recharge_tran_amt));
				switch (Integer.parseInt(recharge_type)){
					case 0:
						tradeOffline.setPayType((byte)BizEnum.PaymentType.NetBankCardQuick.getType());
						tradeOffline.setIsWallet(Boolean.FALSE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());
						break;
					case 1://微信
						tradeOffline.setPayType((byte)BizEnum.PaymentType.WebChat.getType());
						tradeOffline.setIsWallet(Boolean.FALSE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());
						break;
					case 2://微信付款码
						tradeOffline.setPayType((byte)BizEnum.PaymentType.WebChat.getType());
						tradeOffline.setIsWallet(Boolean.FALSE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.Scan.getType());
						break;
					case 3://支付宝付款码
						tradeOffline.setPayType((byte)BizEnum.PaymentType.AliPay.getType());
						tradeOffline.setIsWallet(Boolean.FALSE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.Scan.getType());
						break;
					case 4://外部支付宝
						tradeOffline.setPayType((byte)BizEnum.PaymentType.AliPay.getType());
						tradeOffline.setIsWallet(Boolean.TRUE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.AppOut.getType());
						break;
					case 5://外部微信
						tradeOffline.setPayType((byte)BizEnum.PaymentType.WebChat.getType());
						tradeOffline.setIsWallet(Boolean.TRUE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.AppOut.getType());
						break;
					default:
						break;
				}
				tradeOffline.setTransactionStatus((byte)BizEnum.TransactionStatus.Success.getType());
				tradeOffline.setPayAccount(recharge_bank_name);
				tradeOffline.setCrcodeStr(recharge_qrcode);
				tradeOffline.setPayOrderid(recharge_pay_ordernum);
				tradeOffline.setMemo("云流充值");
				//tradeOffline.setGoodType((byte)CommonEnum.GoodType.Goods.getType());
				result = tradeOfflineMapper.insertSelective(tradeOffline);

				logger.info("充值订单ID:"+recharge_id+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
		}

	}

	public void withdrawalTradeDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		int result = 0;
		try {
			//获取所有的订单记录
			List<Map<String, String>> items = dbUitil.getAllWithdrawalTrade();
			for(Map<String, String> item:items){
				String withdrawal_id = item.get("withdrawal_id");
				String withdrawal_order_id = item.get("withdrawal_order_id");
				String withdrawal_order_num = item.get("withdrawal_order_num");
				String withdrawal_order_time = item.get("withdrawal_order_time");
				String withdrawal_tran_amt = item.get("withdrawal_tran_amt");
				String withdrawal_to_info = item.get("withdrawal_to_info");
				String withdrawal_to_time = item.get("withdrawal_to_time");
				String withdrawal_order_status = item.get("withdrawal_order_status");
				String withdrawal_status = item.get("withdrawal_status");
				String withdrawal_fee_amt = item.get("withdrawal_fee_amt");
				String sys_orderid = item.get("sys_orderid");
				//////////////////////////////////
				String order_id = item.get("order_id");
				String order_type = item.get("order_type");
				String order_userid = item.get("order_userid");
				String order_userid_phone = item.get("order_userid_phone");
				String order_groupid = item.get("order_groupid");
				String order_merchantid = item.get("order_merchantid");
				String order_orgtrandatetime = item.get("order_orgtrandatetime");
				String order_systrace_num = item.get("order_systrace_num");
				String order_resp_code = item.get("order_resp_code");
				String order_msg_txt = item.get("order_msg_txt");
				String order_datetime = item.get("order_datetime");
				String relate_order_id = item.get("relate_order_id");

				//查询新的会员id
				Member ordermember = memberMapper.queryNameByPhone(order_userid_phone,GROUP_Id);
				if(ordermember==null)
					continue;

				TradeOffline tradeOffline = new TradeOffline();
				Date ordertime = new Date(Long.parseLong(withdrawal_to_time)*1000);
				tradeOffline.setGmtCreate(ordertime);
				tradeOffline.setGmtModified(ordertime);
				tradeOffline.setGroupId(GROUP_Id);
				tradeOffline.setOrderId(withdrawal_order_num);
				tradeOffline.setPayerId(ordermember.getId());
				tradeOffline.setPayerName(ordermember.getName());
				tradeOffline.setPayerType((byte)CommonEnum.UserType.User.getType());
				tradeOffline.setReceiverId(String.valueOf(ordermember.getId()));
				tradeOffline.setReceiverName(ordermember.getName());
				tradeOffline.setReceiverType((byte)CommonEnum.UserType.User.getType());

				tradeOffline.setOrderAmount(Integer.parseInt(withdrawal_tran_amt==null?"0":withdrawal_tran_amt));
				tradeOffline.setRealAmount(Integer.parseInt(withdrawal_tran_amt==null?"0":withdrawal_tran_amt));
				tradeOffline.setDiscountAmount(Integer.parseInt(withdrawal_fee_amt==null?"0":withdrawal_fee_amt));
				switch (Integer.parseInt(order_type)){
					case 10://提现
						tradeOffline.setTransactionType((byte)BizEnum.TransactionType.Withdraw.getType());
						tradeOffline.setPayType((byte)BizEnum.PaymentType.Wallet.getType());
						tradeOffline.setIsWallet(Boolean.TRUE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());
						break;
					case 26://信用卡还款
						tradeOffline.setTransactionType((byte)BizEnum.TransactionType.CreditCardRepay.getType());
						tradeOffline.setPayType((byte)BizEnum.PaymentType.Wallet.getType());
						tradeOffline.setIsWallet(Boolean.TRUE);
						tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());
						break;
					default:
						break;
				}
				tradeOffline.setTransactionStatus((byte)BizEnum.TransactionStatus.Success.getType());
				tradeOffline.setMemo(withdrawal_to_info);
				tradeOffline.setPayOrderid(sys_orderid);
				//tradeOffline.setGoodType((byte)CommonEnum.GoodType.Goods.getType());
				result = tradeOfflineMapper.insertSelective(tradeOffline);

				logger.info("提现订单ID:"+withdrawal_id+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
		}

	}

	public void oilCardRechargeTradeDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		int result = 0;
		try {
			//获取所有的订单记录
			List<Map<String, String>> items = dbUitil.getAllOilCardRechargeTrade();
			for(Map<String, String> item:items){
				String oilOrderId = item.get("id");
				String payment_order_id = item.get("payment_order_id");
				String member_id = item.get("member_id");
				String oilcard_number = item.get("oilcard_number");
				String payment_type = item.get("payment_type");
				String payment_status = item.get("payment_status");
				String payment_amount = item.get("payment_amount");
				String recharge_amount = item.get("recharge_amount");
				String oilcard_owner = item.get("oilcard_owner");
				String oilcard_type = item.get("oilcard_type");
				String oilcard_phone = item.get("oilcard_phone");
				String payment_result_cord = item.get("payment_result_cord");
				String payment_time = item.get("payment_time");
				String order_create_time = item.get("order_create_time");
				String pay_order_id = item.get("pay_order_id");
				String oilcard_ordernum = item.get("oilcard_ordernum");
				String order_package_type = item.get("order_package_type");
				String oilcard_package_id = item.get("oilcard_package_id");
				String order_status = item.get("order_status");
				//////////////////////////////////
				String order_userid_phone = item.get("order_userid_phone");
				//查询新的会员id
				Member ordermember = memberMapper.queryNameByPhone(order_userid_phone,GROUP_Id);
				if(ordermember==null)
					continue;

				

				//仅处理成功的交易
				TradeOffline tradeOffline = null;
                if("2".equals(payment_status) && StringUtil.notEmpty(payment_time)) {
					tradeOffline = new TradeOffline();
					Date ordertime = DateUtil.fomatDate(payment_time,DateUtil.sdfTime);
					tradeOffline.setGmtCreate(ordertime);
					tradeOffline.setGmtModified(ordertime);
					tradeOffline.setGroupId(GROUP_Id);
					//订单号
					tradeOffline.setOrderId(oilcard_ordernum);
					tradeOffline.setPayerId(ordermember.getId());
					tradeOffline.setPayerName(ordermember.getName());
					tradeOffline.setPayerType((byte) CommonEnum.UserType.User.getType());
					tradeOffline.setReceiverId(String.valueOf(ordermember.getId()));
					tradeOffline.setReceiverName(ordermember.getName());
					tradeOffline.setReceiverType((byte) CommonEnum.UserType.User.getType());
					tradeOffline.setTransactionType((byte) BizEnum.TransactionType.Consumption.getType());
					tradeOffline.setOrderAmount(Integer.parseInt(recharge_amount == null ? "0" : recharge_amount));
					tradeOffline.setRealAmount(Integer.parseInt(recharge_amount == null ? "0" : recharge_amount));
					switch (Integer.parseInt(payment_type)) {
						case 1://支付宝
							tradeOffline.setPayType((byte) BizEnum.PaymentType.AliPay.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							tradeOffline.setSubType((byte) BizEnum.PaymentScene.Online.getType());
							break;
						case 2://微信
							tradeOffline.setPayType((byte) BizEnum.PaymentType.WebChat.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							tradeOffline.setSubType((byte) BizEnum.PaymentScene.Online.getType());
							break;
						case 3://银行卡
							tradeOffline.setPayType((byte) BizEnum.PaymentType.NetBankCardQuick.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							tradeOffline.setSubType((byte) BizEnum.PaymentScene.Online.getType());
							break;
						case 4://余额
							tradeOffline.setPayType((byte) BizEnum.PaymentType.Wallet.getType());
							tradeOffline.setIsWallet(Boolean.TRUE);
							tradeOffline.setSubType(null);
							break;
						default:
							break;
					}
					tradeOffline.setTransactionStatus((byte) BizEnum.TransactionStatus.Success.getType());
					tradeOffline.setMemo("OilRecharge");
					result = tradeOfflineMapper.insertSelective(tradeOffline);
				}
                
              //插入云流交易表
				YsOilcardOrder ysOilcardOrder=new YsOilcardOrder();
				ysOilcardOrder.setPaymentOrderId(payment_order_id);
				ysOilcardOrder.setMemberId(member_id);
				ysOilcardOrder.setOilcardOrdernum(oilcard_ordernum);
				ysOilcardOrder.setOilcardNumber(oilcard_number);
				switch (Integer.parseInt(payment_type)) {
				case 1://支付宝
					ysOilcardOrder.setPaymentType( BizEnum.PaymentType.AliPay.getType());
					break;
				case 2://微信
					ysOilcardOrder.setPaymentType( BizEnum.PaymentType.WebChat.getType());
					break;
				case 3://银行卡
					ysOilcardOrder.setPaymentType( BizEnum.PaymentType.NetBankCardQuick.getType());
					break;
				case 4://余额
					ysOilcardOrder.setPaymentType( BizEnum.PaymentType.Wallet.getType());
					
					break;
				default:
					break;
			}
				
				
				ysOilcardOrder.setPaymentStatus(Integer.parseInt(payment_status));
				ysOilcardOrder.setPaymentAmount(Integer.parseInt(payment_amount == null ? "0" : payment_amount));
				ysOilcardOrder.setRechargeAmount(Integer.parseInt(recharge_amount == null ? "0" : recharge_amount));
				ysOilcardOrder.setOilcardOwner(oilcard_owner);
				ysOilcardOrder.setOilcardType(oilcard_type);
				ysOilcardOrder.setOilcardPhone(oilcard_phone);
				ysOilcardOrder.setPaymentResultCord(payment_result_cord);
				ysOilcardOrder.setPaymentTime(DateUtil.fomatDate(payment_time,DateUtil.sdfTime));
				ysOilcardOrder.setOrderPackageType(order_package_type==null?null:Integer.parseInt(order_package_type));
				//关联套餐ID设置(switch case或者直接用原来Id值,取决于数据方案)
				ysOilcardOrder.setOilcardPackageId(oilcard_package_id==null?null:Long.parseLong(oilcard_package_id));
				ysOilcardOrder.setOrderStatus(order_status==null?null:Integer.parseInt(order_status));
				ysOilcardOrder.setOrderCreateTime(DateUtil.fomatDate(order_create_time,DateUtil.sdfTime));
				ysOilcardOrder.setId(Long.parseLong(oilOrderId));
				if(tradeOffline!=null){
					ysOilcardOrder.setPayOrderId(tradeOffline.getId());
				}
				//result = ysOilcardOrderMapper.insertSelective(ysOilcardOrder);
				result = ysOilcardOrderMapper.insert(ysOilcardOrder);
				
				//处理油卡订单 充值列表 ，如果油卡订单的id保持不变,对应的，充值订单 ，源数据导出 补充值的订单 ， ,只需要直接导入sql 就可以
				
//				List<Map<String, String>> oilCardCharges = dbUitil.getAllOilCardRechargeInfo(oilOrderId);
//				
//				
//				for(Map<String, String>oilCardCharge:oilCardCharges ){
//					//处理补充值订单列表
//					String chargeInfoId=oilCardCharge.get("id");
//					List<Map<String, String>> reOilCardCharges = dbUitil.getAllReOilCardRecharge(oilOrderId,chargeInfoId);
//					for(Map<String, String> reOilCardChages:reOilCardCharges){
//						
//					}
//				}
				
				logger.info("油卡订单ID:"+payment_order_id+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
		}

	}

	public void flowRechargeTradeDeal() throws Exception{

		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态

		int result = 0;
		try {
			//获取所有的订单记录
			List<Map<String, String>> items = dbUitil.getAllFlowRechargeTrade();
			for(Map<String, String> item:items){
				String pay_order_num = item.get("pay_order_num");
				String sys_order_number = item.get("sys_order_number");
				String order_number = item.get("order_number");
				String pay_date = item.get("pay_date");
				String order_id = item.get("order_id");
				String pay_amount = item.get("pay_amount");
				String pay_type = item.get("pay_type");
				String notify_respond = item.get("notify_respond");
				String notify_url = item.get("notify_url");
				String pay_status = item.get("pay_status");
				//////////////////////////////////
				String order_type = item.get("order_type");
				String order_userid = item.get("order_userid");
				String order_userid_phone = item.get("order_userid_phone");
				String order_groupid = item.get("order_groupid");
				String order_merchantid = item.get("order_merchantid");
				String order_orgtrandatetime = item.get("order_orgtrandatetime");
				String order_systrace_num = item.get("order_systrace_num");
				String order_resp_code = item.get("order_resp_code");
				String order_msg_txt = item.get("order_msg_txt");
				String order_datetime = item.get("order_datetime");
				String relate_order_id = item.get("relate_order_id");

				//查询新的会员id
				Member ordermember = memberMapper.queryNameByPhone(order_userid_phone,GROUP_Id);
				if(ordermember==null)
					continue;

				TradeOffline tradeOffline = new TradeOffline();
				//仅处理成功的交易
				if("1".equals(pay_status) && StringUtil.notEmpty(pay_date)) {

					Date ordertime = DateUtil.fomatDate(pay_date,DateUtil.sdfTime);
					tradeOffline.setGmtCreate(ordertime);
					tradeOffline.setGmtModified(ordertime);
					tradeOffline.setGroupId(GROUP_Id);
					//订单号
					tradeOffline.setOrderId(sys_order_number);
					tradeOffline.setPayerId(ordermember.getId());
					tradeOffline.setPayerName(ordermember.getName());
					tradeOffline.setPayerType((byte) CommonEnum.UserType.User.getType());
					tradeOffline.setReceiverId(String.valueOf(ordermember.getId()));
					tradeOffline.setReceiverName(ordermember.getName());
					tradeOffline.setReceiverType((byte) CommonEnum.UserType.User.getType());
					tradeOffline.setTransactionType((byte) BizEnum.TransactionType.Consumption.getType());
					tradeOffline.setOrderAmount(Integer.parseInt(pay_amount == null ? "0" : pay_amount));
					tradeOffline.setRealAmount(Integer.parseInt(pay_amount == null ? "0" : pay_amount));
					switch (Integer.parseInt(pay_type)) {
						case 1://支付宝
							tradeOffline.setPayType((byte) BizEnum.PaymentType.AliPay.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							tradeOffline.setSubType((byte) BizEnum.PaymentScene.Online.getType());
							break;
						case 2://微信
							tradeOffline.setPayType((byte) BizEnum.PaymentType.WebChat.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							tradeOffline.setSubType((byte) BizEnum.PaymentScene.Online.getType());
							break;
						case 3://银行卡
							tradeOffline.setPayType((byte) BizEnum.PaymentType.NetBankCardQuick.getType());
							tradeOffline.setIsWallet(Boolean.FALSE);
							tradeOffline.setSubType((byte) BizEnum.PaymentScene.Online.getType());
							break;
						case 4://余额
							tradeOffline.setPayType((byte) BizEnum.PaymentType.Wallet.getType());
							tradeOffline.setIsWallet(Boolean.TRUE);
							tradeOffline.setSubType(null);
							break;
						default:
							break;
					}
					tradeOffline.setTransactionStatus((byte) BizEnum.TransactionStatus.Success.getType());
					tradeOffline.setMemo("FlowRecharge");
					result = tradeOfflineMapper.insertSelective(tradeOffline);
				}

				//插入云流交易表
				YsFlowChargeOrder ysFlowChargeOrder = new YsFlowChargeOrder();
				ysFlowChargeOrder.setPayOrderNum(pay_order_num);
				ysFlowChargeOrder.setSysOrderNumber(sys_order_number);
				ysFlowChargeOrder.setOrderNumber(order_number);
				ysFlowChargeOrder.setPayDate(DateUtil.fomatDate(pay_date,DateUtil.sdfTime));
				ysFlowChargeOrder.setOrderId(tradeOffline.getId());
				ysFlowChargeOrder.setPayAmount(Integer.parseInt(pay_amount == null ? "0" : pay_amount));
				//ysFlowChargeOrder.setPayType(Integer.parseInt(pay_type == null ? "0" : pay_type));
				ysFlowChargeOrder.setPayType(Integer.valueOf(tradeOffline.getPayType()==null?0:tradeOffline.getPayType()));
				
				//ysFlowChargeOrder.setPayType(Integer.valueOf(tradeOffline.getPayType()));
				ysFlowChargeOrder.setNotifyRespond(Integer.parseInt(notify_respond == null ? "0" : notify_respond));
				ysFlowChargeOrder.setNotifyUrl(notify_url);
				ysFlowChargeOrder.setPayStatus(Integer.parseInt(pay_status == null ? "0" : pay_status));
				ysFlowChargeOrder.setYsMemberId(ordermember.getThirdUserId());
                result = flowChargeMapper.insert(ysFlowChargeOrder);

				logger.info("流量卡订单ID:"+pay_order_num+"处理完成...");
			}

			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			e.printStackTrace();
			//logger.error("commit", e);
		}

	}
}

